package controle;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;


public class CriaConexaoWorker extends Thread implements SocketControlConstants
{
	private ControlePortas controlePortas;

	public CriaConexaoWorker(ControlePortas controlePortas)
	{
		this.controlePortas = controlePortas;
	}
	
	public void run()
	{
		Socket socket;
		try
		{
			socket = new Socket(this.controlePortas.getIpDestino(), SocketControlConstants.portaConexaoChatWorker);
			ObjectOutputStream msg = new ObjectOutputStream(socket.getOutputStream());
			//-
			System.out.println("CriaConexaoWorker -> Porta de Entrada: " + this.controlePortas.getIpFonte() + "\nCriaConexaoWorker -> Porta de Saida: " + this.controlePortas.getIpDestino());
			//-
			msg.writeObject(controlePortas);
			socket.close();
		}
		 catch (UnknownHostException e) 
		 {
				e.printStackTrace();
		 } 
		 catch (IOException e) 
		 {
				e.printStackTrace();
		 } 
	}
}
